package com.ydgk.service;

import com.ydgk.bean.Pclass;
import com.ydgk.dao.PclassDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PclassService {
    PclassDao pclassDao=new PclassDao();
    public Map AdminSearch(Integer pageNumber){
        int maxPage=pclassDao.maxPage();
        if(pageNumber > maxPage){
            pageNumber = maxPage;
        }
        if(pageNumber < 1){
            pageNumber = 1;
        }
        String pageCode=pclassDao.genPagination("PclassServlet.action",maxPage,pageNumber,"flag=findPclass");
        List<Pclass> pclassList=pclassDao.paging(pageNumber);
        HashMap map=new HashMap();
        map.put("pageCode",pageCode);
        map.put("pclassList",pclassList);
        return map;
    }
    public int saveOrUpdate(Pclass pclass){

        if(pclass.getId() != null && pclass.getId() != 0 ){
            //修改
            return pclassDao.updateById(pclass);
        }else{
            //添加
            return pclassDao.save(pclass);
        }
    }
    public int deleteById(int id){
        return pclassDao.deleteById(id);
    }
    public List<Pclass> findAll(){
        return pclassDao.findAll();
    }
}
